package com.supermap.desktop.develop.workspacemigration.ui;

import com.supermap.data.EngineType;
import com.supermap.data.SteppedListener;
import com.supermap.desktop.controls.ui.controls.DialogResult;
import com.supermap.desktop.controls.ui.controls.SmDialog;
import com.supermap.desktop.controls.ui.controls.button.SmButton;
import com.supermap.desktop.controls.ui.controls.labels.SmLabelHelp;
import com.supermap.desktop.controls.ui.controls.progress.SmDialogProgressTotal;
import com.supermap.desktop.controls.ui.controls.textFields.SmPasswordField;
import com.supermap.desktop.controls.utilities.ComponentFactory;
import com.supermap.desktop.core.Application;
import com.supermap.desktop.core.Interface.IOutput;
import com.supermap.desktop.core.Interface.helps.implement.DefaultHelpProvider;
import com.supermap.desktop.core.Time;
import com.supermap.desktop.core.TimeType;
import com.supermap.desktop.core.progress.Interface.UpdateProgressCallable;
import com.supermap.desktop.develop.workspacemigration.internalhelpers.InternalHelper;
import com.supermap.desktop.develop.workspacemigration.migration.MigrationConfig;
import com.supermap.desktop.develop.workspacemigration.migration.WorkspaceMigration;
import com.supermap.desktop.develop.workspacemigration.migration.WorkspaceMigrationFactory;
import com.supermap.desktop.develop.workspacemigration.migration.events.MigrateSteppedEvent;
import com.supermap.desktop.develop.workspacemigration.ui.helpers.WorkspaceMigrationDialogHelper;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;

/**
 * @author SuperMap
 */
public class WorkspaceMigrationDialog extends SmDialog {

    private SmButton buttonOK;
    private SmButton buttonCancel;

    private JPanel mainPanel;

    private JPanel srcPanel;
    private JLabel srcIPLbl;
    private JTextField srcIPTxt;
    private JLabel srcPortLbl;
    private JTextField srcPortTxt;
    private JLabel srcDatabaseNameLbl;
    private JTextField srcDatabaseNameTxt;
    private JLabel srcUserNameLbl;
    private JTextField srcUserNameTxt;
    private JLabel srcPasswordLbl;
    private JTextField srcPasswordTxt;
    private JLabel srcEngineTypeLbl;
    private JComboBox<EngineType> srcEngineTypeCmb;
    private JLabel srcWorkspaceNameLbl;
    private JComboBox<String> srcWorkspaceNameCmb;
    private JCheckBox isBatchMigrationCbx;

    private JPanel tarPanel;
    private JLabel tarIPLbl;
    private JTextField tarIPTxt;
    private JLabel tarPortLbl;
    private JTextField tarPortTxt;
    private JLabel tarDatabaseNameLbl;
    private JTextField tarDatabaseNameTxt;
    private SmLabelHelp tarUserNameLbl;
    private JTextField tarUserNameTxt;
    private JLabel tarPasswordLbl;
    private JTextField tarPasswordTxt;
    private JLabel tarEngineTypeLbl;
    private JComboBox<EngineType> tarEngineTypeCmb;

    public WorkspaceMigrationDialog() {
        super();

        this.setSize(new Dimension(460, 560));
        initComponents();
        initComponentsStatus();
        initLayout();
        initResources();
        registerEvents();
        componentList.add(buttonOK);
        componentList.add(buttonCancel);
        this.setFocusTraversalPolicy(policy);
    }

    private void initComponents() {
        mainPanel = new JPanel();

        srcPanel = new JPanel();
        srcPanel.setBorder(BorderFactory.createTitledBorder("源数据库"));
        srcIPLbl = new JLabel("IP:");
        srcIPTxt = new JFormattedTextField();
        srcPortLbl = new JLabel("端口:");
        srcPortTxt = new JFormattedTextField();
        srcDatabaseNameLbl = new JLabel("数据库名称:");
        srcDatabaseNameTxt = new JFormattedTextField();
        srcUserNameLbl = new JLabel("用户名:");
        srcUserNameTxt = new JFormattedTextField();
        srcPasswordLbl = new JLabel("密码:");
        srcPasswordTxt = new SmPasswordField();
        srcEngineTypeLbl = new JLabel("数据库引擎:");
        srcEngineTypeCmb = new JComboBox<>();
        srcEngineTypeCmb.addItem(EngineType.POSTGRESQL);
        srcEngineTypeCmb.addItem(EngineType.PGGIS);
        srcWorkspaceNameLbl = new JLabel("工作空间:");
        srcWorkspaceNameCmb = new JComboBox<>();

        tarPanel = new JPanel();
        tarPanel.setBorder(BorderFactory.createTitledBorder("目标数据库"));
        tarIPLbl = new JLabel("IP:");
        tarIPTxt = new JFormattedTextField();
        tarPortLbl = new JLabel("端口:");
        tarPortTxt = new JFormattedTextField();
        tarDatabaseNameLbl = new JLabel("数据库名称:");
        tarDatabaseNameTxt = new JFormattedTextField();
        DefaultHelpProvider tarUserHelpProvider = new DefaultHelpProvider();
        tarUserHelpProvider.setHelpTitle("用户限制");
        tarUserHelpProvider.setHelpText("当目标数据库为 DM 时，需要使用管理员权限的账户");
        tarUserNameLbl = new SmLabelHelp(tarUserHelpProvider);
        tarUserNameLbl.setText("用户名:");
        tarUserNameLbl.setIcon(InternalHelper.HelpIcon);
        tarUserNameTxt = new JFormattedTextField();
        tarPasswordLbl = new SmLabelHelp(tarUserHelpProvider);
        tarPasswordLbl.setText("密码:");
        tarPasswordLbl.setIcon(InternalHelper.HelpIcon);
        tarPasswordTxt = new SmPasswordField();
        tarEngineTypeLbl = new JLabel("数据库引擎:");
        tarEngineTypeCmb = new JComboBox<>();
        tarEngineTypeCmb.addItem(EngineType.DM);

        buttonOK = ComponentFactory.createButtonOK();
        buttonCancel = ComponentFactory.createButtonCancel();
        isBatchMigrationCbx = new JCheckBox("批量迁移工作空间");
        isBatchMigrationCbx.setSelected(false);

        MigrationConfig migrationConfig = InternalHelper.loadMigrationConfig();
        if (migrationConfig != null) {
            srcIPTxt.setText(migrationConfig.getSrcIP());
            srcPortTxt.setText(migrationConfig.getSrcPort());
            srcDatabaseNameTxt.setText(migrationConfig.getSrcDatabaseName());
            srcUserNameTxt.setText(migrationConfig.getSrcUsername());
            srcPasswordTxt.setText(migrationConfig.getSrcPassword());
            srcEngineTypeCmb.setSelectedItem(EngineType.parse(EngineType.class, migrationConfig.getSrcEngineType()));

            tarIPTxt.setText(migrationConfig.getTarIP());
            tarPortTxt.setText(migrationConfig.getTarPort());
            tarDatabaseNameTxt.setText(migrationConfig.getTarDatabaseName());
            tarUserNameTxt.setText(migrationConfig.getTarUsername());
            tarPasswordTxt.setText(migrationConfig.getTarPassword());
            tarEngineTypeCmb.setSelectedItem(EngineType.parse(EngineType.class, migrationConfig.getTarEngineType()));
        }

        buttonOK.setEnabled(checkButtonOKStatus());
        checkTargetDatabaseNameTxtStatus();
    }

    private void initComponentsStatus() {
        buttonOK.setEnabled(checkButtonOKStatus());
    }

    private void initLayout() {
        setDialogHelpProvider(new WorkspaceMigrationDialogHelper());

        this.setLayout(new BorderLayout());

        mainPanel.setLayout(new GridBagLayout());
        this.add(mainPanel, BorderLayout.CENTER);

        mainPanel.add(srcPanel, new GridBagConstraints(0, 0, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.setLayout(new GridBagLayout());
        srcPanel.add(srcIPLbl, new GridBagConstraints(0, 0, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcIPTxt, new GridBagConstraints(1, 0, 2, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcPortLbl, new GridBagConstraints(0, 1, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcPortTxt, new GridBagConstraints(1, 1, 2, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcDatabaseNameLbl, new GridBagConstraints(0, 2, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcDatabaseNameTxt, new GridBagConstraints(1, 2, 2, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcUserNameLbl, new GridBagConstraints(0, 3, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcUserNameTxt, new GridBagConstraints(1, 3, 2, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcPasswordLbl, new GridBagConstraints(0, 4, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcPasswordTxt, new GridBagConstraints(1, 4, 2, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcEngineTypeLbl, new GridBagConstraints(0, 5, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcEngineTypeCmb, new GridBagConstraints(1, 5, 2, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcWorkspaceNameLbl, new GridBagConstraints(0, 6, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        srcPanel.add(srcWorkspaceNameCmb, new GridBagConstraints(1, 6, 1, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));

        mainPanel.add(tarPanel, new GridBagConstraints(0, 1, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.setLayout(new GridBagLayout());
        tarPanel.add(tarIPLbl, new GridBagConstraints(0, 0, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.add(tarIPTxt, new GridBagConstraints(1, 0, 1, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.add(tarPortLbl, new GridBagConstraints(0, 1, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.add(tarPortTxt, new GridBagConstraints(1, 1, 1, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.add(tarDatabaseNameLbl, new GridBagConstraints(0, 2, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.add(tarDatabaseNameTxt, new GridBagConstraints(1, 2, 1, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.add(tarUserNameLbl, new GridBagConstraints(0, 3, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.add(tarUserNameTxt, new GridBagConstraints(1, 3, 1, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.add(tarPasswordLbl, new GridBagConstraints(0, 4, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.add(tarPasswordTxt, new GridBagConstraints(1, 4, 1, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.add(tarEngineTypeLbl, new GridBagConstraints(0, 5, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));
        tarPanel.add(tarEngineTypeCmb, new GridBagConstraints(1, 5, 1, 1, 10, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));

        mainPanel.add(isBatchMigrationCbx, new GridBagConstraints(0, 2, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(2, 2, 2, 2), 0, 0));

        JPanel buttonPanel = ComponentFactory.createButtonPanel(buttonOK, buttonCancel);
        buttonPanel.setBorder(new EmptyBorder(5, 10, 10, 10));
        this.add(buttonPanel, BorderLayout.SOUTH);
    }

    private void initResources() {
        this.setTitle("迁移工作空间");
    }

    private void registerEvents() {
        buttonOK.addActionListener(actionListenerOK);
        buttonCancel.addActionListener(actionListenerCancel);
        isBatchMigrationCbx.addActionListener(actionListenerBatch);

        srcIPTxt.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                buttonOK.setEnabled(checkButtonOKStatus());
            }
        });
        srcPortTxt.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                buttonOK.setEnabled(checkButtonOKStatus());
            }
        });
        srcDatabaseNameTxt.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                buttonOK.setEnabled(checkButtonOKStatus());
            }
        });
        srcUserNameTxt.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                buttonOK.setEnabled(checkButtonOKStatus());
            }
        });
        srcPasswordTxt.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                buttonOK.setEnabled(checkButtonOKStatus());
            }
        });
        srcWorkspaceNameCmb.addPopupMenuListener(new PopupMenuListener() {
            @Override
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                loadWorkspaceNamesFromDatabase();
                buttonOK.setEnabled(checkButtonOKStatus());
            }

            @Override
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            }

            @Override
            public void popupMenuCanceled(PopupMenuEvent e) {
            }
        });

        tarIPTxt.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                buttonOK.setEnabled(checkButtonOKStatus());
            }
        });
        tarPortTxt.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                buttonOK.setEnabled(checkButtonOKStatus());
            }
        });
        tarUserNameTxt.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                buttonOK.setEnabled(checkButtonOKStatus());
            }
        });
        tarPasswordTxt.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                buttonOK.setEnabled(checkButtonOKStatus());
            }
        });
        tarEngineTypeCmb.addItemListener(e -> checkTargetDatabaseNameTxtStatus());
    }

    private final ActionListener actionListenerOK = e -> {
        updateMigrationConfig();
        run();
        setDialogResult(DialogResult.OK);
        dispose();
    };

    private final ActionListener actionListenerCancel = e -> dispose();

    private final ActionListener actionListenerBatch = e -> {
        boolean isBatchMigrationCbxSelected = isBatchMigrationCbx.isSelected();
        srcWorkspaceNameLbl.setEnabled(!isBatchMigrationCbxSelected);
        srcWorkspaceNameCmb.setEnabled(!isBatchMigrationCbxSelected);
        buttonOK.setEnabled(checkButtonOKStatus());
    };

    private void loadWorkspaceNamesFromDatabase() {
        String ip = srcIPTxt.getText();
        String port = srcPortTxt.getText();
        String databaseName = srcDatabaseNameTxt.getText();
        String username = srcUserNameTxt.getText();
        String password = srcPasswordTxt.getText();
        EngineType engineType = (EngineType) srcEngineTypeCmb.getSelectedItem();

        if (ip == null || ip.equals("") ||
                port == null || port.equals("") ||
                databaseName == null || databaseName.equals("") ||
                username == null || username.equals("") ||
                password == null || password.equals("")) {
            return;
        }

        updateMigrationConfig();

        srcWorkspaceNameCmb.removeAllItems();
        ArrayList<String> workspaceNames = InternalHelper.queryWorkspaceNames(ip, port, databaseName, username, password, engineType);
        for (String workspaceName : workspaceNames) {
            srcWorkspaceNameCmb.addItem(workspaceName);
        }
    }

    private void run() {
        IOutput output = Application.getActiveApplication().getOutput();

        String srcIP = srcIPTxt.getText();
        String srcPort = srcPortTxt.getText();
        String srcDatabaseName = srcDatabaseNameTxt.getText();
        String srcUserName = srcUserNameTxt.getText();
        String srcPassword = srcPasswordTxt.getText();
        EngineType srcEngineType = (EngineType) srcEngineTypeCmb.getSelectedItem();
        String srcWorkspaceName = (String) srcWorkspaceNameCmb.getSelectedItem();

        String tarIP = tarIPTxt.getText();
        String tarPort = tarPortTxt.getText();
        String tarDatabaseName = tarDatabaseNameTxt.getText();
        String tarUsername = tarUserNameTxt.getText();
        String tarPassword = tarPasswordTxt.getText();
        EngineType tarEngineType = (EngineType) tarEngineTypeCmb.getSelectedItem();

        boolean isBatchMigration = isBatchMigrationCbx.isSelected();

        try {
            WorkspaceMigration workspaceMigration = WorkspaceMigrationFactory.createWorkspaceMigration(srcIP, srcPort,
                    srcDatabaseName, srcUserName, srcPassword, srcEngineType, srcWorkspaceName, tarIP, tarPort,
                    tarDatabaseName, tarUsername, tarPassword, tarEngineType, isBatchMigration);
            SmDialogProgressTotal smDialogProgressTotal = new SmDialogProgressTotal();
            smDialogProgressTotal.setLabelRemainTimeVisible(false);
            smDialogProgressTotal.setButtonCancelVisible(false);
            SteppedListener workspaceMigrationSteppedListener = (steppedEvent) -> {
                MigrateSteppedEvent migrateSteppedEvent = (MigrateSteppedEvent) steppedEvent;
                smDialogProgressTotal.setTitle(migrateSteppedEvent.getTitle());
                smDialogProgressTotal.updateProgress(migrateSteppedEvent.getSubPercent(), migrateSteppedEvent.getPercent(),
                        migrateSteppedEvent.getSubMessage(), migrateSteppedEvent.getMessage(), "", migrateSteppedEvent.getPercent(), 100);
            };
            workspaceMigration.addSteppedListener(workspaceMigrationSteppedListener);
            smDialogProgressTotal.doWork(new UpdateProgressCallable() {
                @Override
                public Boolean call() {
                    long migrateStartTime = System.currentTimeMillis();
                    boolean migratedResult = workspaceMigration.migrate();
                    long migrateEndTime = System.currentTimeMillis();
                    output.output((migratedResult ? "工作空间迁移成功！" : "工作空间迁移失败！").concat(" ---- 共计耗时：")
                            .concat(Time.toString(migrateEndTime - migrateStartTime, TimeType.MILLISECOND)));
                    workspaceMigration.removeSteppedListener(workspaceMigrationSteppedListener);
                    workspaceMigration.dispose();
                    return true;
                }
            });
        } catch (Exception e) {
            output.output(e);
        }
    }

    private boolean checkButtonOKStatus() {
        String srcIP = srcIPTxt.getText();
        String srcPort = srcPortTxt.getText();
        String srcDatabaseName = srcDatabaseNameTxt.getText();
        String srcUserName = srcUserNameTxt.getText();
        String srcPassword = srcPasswordTxt.getText();
        Object srcWorkspaceName = srcWorkspaceNameCmb.getSelectedItem();

        String tarIP = tarIPTxt.getText();
        String tarPort = tarPortTxt.getText();
        String tarUsername = tarUserNameTxt.getText();
        String tarPassword = tarPasswordTxt.getText();

        boolean isBatchMigration = isBatchMigrationCbx.isSelected();

        return srcIP != null && !srcIP.equals("") &&
                srcPort != null && !srcPort.equals("") &&
                srcDatabaseName != null && !srcDatabaseName.equals("") &&
                srcUserName != null && !srcUserName.equals("") &&
                srcPassword != null && !srcPassword.equals("") &&
                (srcWorkspaceName != null && !srcWorkspaceName.toString().equals("") || isBatchMigration) &&
                tarIP != null && !tarIP.equals("") &&
                tarPort != null && !tarPort.equals("") &&
                tarUsername != null && !tarUsername.equals("") &&
                tarPassword != null && !tarPassword.equals("");
    }

    private void checkTargetDatabaseNameTxtStatus() {
        EngineType tarEngineType = (EngineType) tarEngineTypeCmb.getSelectedItem();
        tarDatabaseNameLbl.setEnabled(tarEngineType != EngineType.DM);
        tarDatabaseNameTxt.setEnabled(tarEngineType != EngineType.DM);
    }

    private void updateMigrationConfig() {
        MigrationConfig migrationConfig = new MigrationConfig(srcIPTxt.getText(), srcPortTxt.getText(),
                srcDatabaseNameTxt.getText(), srcUserNameTxt.getText(), srcPasswordTxt.getText(),
                srcEngineTypeCmb.getSelectedItem().toString(), tarIPTxt.getText(), tarPortTxt.getText(),
                tarDatabaseNameTxt.getText(), tarUserNameTxt.getText(), tarPasswordTxt.getText(),
                tarEngineTypeCmb.getSelectedItem().toString());
        InternalHelper.updateMigrationConfig(migrationConfig);
    }
}

